exports.strip_tags=function(str,allowtags){
    allowtags=(allowtags==undefined||allowtags=="")?"":allowtags;
    if(str==undefined||str=="") return "";

    allowtags=allowtags.replace(/<([^<>]+)>/gi,"$1|").replace(/(<|>)+/gi,"|").replace(/\|$/,"");
    if(allowtags!=""){
        var objRegExp = new RegExp("<(?!\\/?(?:"+allowtags+"))[^<>]*>", "igm");
        str=str.replace(objRegExp,"");
    }else{
        str=this.preg_replace("<[^<>]*>","",str);
    }
    return str;
}

exports.isgbk=function(pagehtml){
    matches=new Array();
    var charset="";
    matches=new Array();
    if (this.preg_match("/<meta[^<>]+charset=(['\"]?)([a-zA-Z0-9\-]+?)\\1/Uisx", pagehtml, matches)) {
        charset = this.str_replace("-", "", this.strtolower(matches[2]));
    }
    if (charset != "utf8") {
        charset = (!this.preg_match("/。|，|？|；/", pagehtml)) ? charset : "utf8";
    }
    return charset.toLowerCase();
}


exports.strip_tags2=function (str,s){
    str=this.strip_tags(str,s);
    str=this.preg_replace("/(desc|alt)=\"([\\s\\S]*)\"/Uisx","\\1=\"\\2\"",str);
    str=this.preg_replace("/\&lt\;.*\&gt\;/Uisx","",str);
    str=this.preg_replace("/<(?!\\/|"+s+"|script|b)[\\s\\S]*(?<!width|height|\\=|\\.)>/Uisx","",str);
    str=this.preg_replace("/<\\/(?!"+s+"|script|b)[\\s\\S]*(?<!width|height|\\=|\\.)>/Uisx","",str);
    return str;
}

exports.strip_jscss= function(str,lie_a)
{
    lie_a=(lie_a==undefined||lie_a=="")?false:lie_a;
    nn=new Array();nn[1]=new Array();
    this.preg_match_all("<script\\b[^<>]*>[\\s\\S]*<\\/\\s*script\\s*\\/?>", str, nn);
    for (i3 = 0; i3 < nn[1].length; i3++) {
        if (this.preg_match("reload|AC_FL_RunContent", nn[0][i3])) {
            if (this.preg_match("http\\:\\/\\/([^<>]*\\.swf)", nn[0][i3], mm)) {
                str = this.str_replace(nn[0][i3], "[media=swf,500,375]"+mm[0]+"[/media]", str);
                continue;
            }
        }
        str = this.str_replace(nn[0][i3], "", str);
    }
    str = this.preg_replace("<SCRIPT\\b[^<>]*>[\\s\\S]*(<\\/\\s*script\\s*\\/?>)", "", str);
    str = this.preg_replace("<select\\b[^<>]*>[\\s\\S]*(<\\/\\s*select\\s*\\/?>)", "", str);
    str = this.preg_replace("<div\\b[^<>]*>([\\s\\S](?!<div))*<\\/script>([\\s\\S](?!<div))*(<\\/\\s*div\\s*\\/?>|$)", "", str);
    str = this.preg_replace("<\\/?br\\s*\\/?>|&lt;\\/br\\s*\\/?&gt;", "\r\n", str);
    str = this.preg_replace("<style\\b[^<>]*>[\\s\\S]*<\\/\\s*style\s*\\/?>", "", str);
    str = this.preg_replace("<img[^<>]*src=\"([^<>]*)\"[^<>]*file=\"([^<>]*)\"[^<>]*>", "<img src=\"\\1\">", str);
    if(!lie_a) str = this.preg_replace("<\\/?a(?=\\>|\\s)[^<>]*>", "", str);
    str = this.preg_replace("\b(?![=\"\\'\\]\\[])(http\\:\\/\\/[^<>]*\\.(jpg|gif|png))", "<img src=\"\\1\">", str);
    str = this.preg_replace("([0-9]{4}\\-[0-9]{1,2}\\-[0-9]{1,2}|(半|[0-9])(小时|天)前)[^<>]*下载附件[^<>]*KB\\)", "", str);
    return str;
}

function uisx(regStr){
    regStr=regStr.replace(/\\'/g,"'");
    regStr=regStr.replace(/(\]|\)|\.|\\s)\*/g,"$1*?").replace(/(\]|\)|\.|\\s)\+/g,"$1+?");//加问号
    regStr=regStr.replace(/\(\?<([^<>]*)>[^\(\)]*\)/gi,"").replace(/(\?\?)+/g,"");//去问号，去捕获标签号（原因不支持）
    regStr=regStr.replace(/\(\?<(\=|\!)([^\(\)]*)\)/gi,"(?:(?:(?!^)\\B|(?!^)\\b)(?$1$2))").replace(/\.(?=\*|\+)/g,"[\\s\\S]");//前置断言和.匹配修改
    regStr=regStr.replace(/\*\?\$/g,"*$");
    regStr=regStr.replace(/\+\?\$/g,"+$");
    return regStr;
}
exports.preg_match=function(regStr, str, nn) {
    regStr = regStr.replace(/^\/([\s\S]*)\/[Uisxmu]*$/, "$1");
    regStr=uisx(regStr);
    //console.log(regStr+"\r\n"+regStr2);
    var objRegExp = new RegExp(regStr, "igm");
    res = objRegExp.exec(str);
    if (nn == undefined) nn = new Array();
    if (null != res) {
        for (irr = 0; irr < res.length; irr++) {
            nn[irr] = (res[irr]==undefined)?"":res[irr];
        }
        return res.length > 0;
    } else {
        return false;
    }
}

exports.preg_count=function(regStr, str){
    var pcountnn=new Array();
    this.preg_match(regStr, str, pcountnn);
    return pcountnn.length;
}

exports.preg_match_all=function(regStr, str, nn) {
    var arr = new Array();
    regStr = regStr.replace(/^\/([\s\S]*)\/[Uisxmue]*$/, "$1");
    group=new Array();
    groupre=/\(\?<([^<>]*)>[^\(\)]*\)/gi;
    while(names=groupre.exec(regStr)!=null){
        if(names.length>0) {
            group.push(names[1]);
        }
    }
    regStr=uisx(regStr);
    var objRegExp = new RegExp(regStr, "igm");
    while ((res = objRegExp.exec(str))!=null) {
        arr.push(res);
    }
    if (nn == undefined){
        nn = new Array();
        nn[0]=new Array();
        nn[1]=new Array();
        nn[1].length=0;
    }
    for (var itt in arr) {
        for (var jtt in arr[itt]) {
            if (!isNaN(jtt)&&!isNaN(itt)) {
                if(nn[jtt]==undefined) nn[jtt] = new Array();
                nn[jtt][itt] = (arr[itt][jtt]==undefined)?"":arr[itt][jtt];
            }
        }
    }
    return nn.length > 0;
}

exports.stripa=function(str)
{
    str = this.preg_replace("/<a\\s?[^<>]*>.*<\\/a>/Uisx", "", str);
    return str;
}

exports.preg_replace=function(regStr, str2, str) {
    if(str==undefined||str==null) return "";
    var arr = new Array();
    regStr = regStr.replace(/^\/([\s\S]*)\/[Uisxmue]*$/, "$1");
    regStr=uisx(regStr);
    var objRegExp = new RegExp(regStr, "igm");
    str2 = str2.replace(/\\([0-9]+)/gmi, "\$$1");
    str = str.replace(objRegExp, str2);
    return str;
}

exports.str_replace=function (regStr, str2, str) {
    str = str.replace(regStr, str2);
    return str;
}

exports.preg_split=function(regStr, str) {
    if(str==undefined||str==null) return [];
    regStr = regStr.replace(/^\/([\s\S]*)\/[Uisxmue]*$/, "$1");
    regStr=uisx(regStr);
    var reg = new RegExp(regStr, "igm");
    return str.split(reg);
}

exports.in_array=function(str, arr) {
    for (i = 0; i < arr.length; i++) {
        if (arr[i] == null) break;
        onestr = arr[i].toString();
        if (onestr == str) {
            return true;
        }
    }
    return false;
}

exports.is_array=function (arr) {
    return typeof arr == "object" && arr.constructor == Array;
}

exports.is_string=function (str){
    return typeof str == "string";
}

exports.is_root=function (str) {
    str = this.trim(str);
    c = preg_count("\\/", str);
    if (str == "" || str == "\\" || c < 3 && this.substr(str, 0, 7) == "http://" || c == 3 && this.substr(str, -1, 1) == "/" && this.substr(str, 0, 7) == "http://") {
        return true;
    }
    return false;
}

exports.trim=function(str) {
    if(str==undefined) return "";
    return str.replace(/(^\s*)|(\s*$)/g, "");
}

exports.substr=function (str, start, end) {
    return str.substring(start, end);
}

exports.preg_count=function (re, str) {
    var regex1 = new RegExp(re, "igm");
    var arrMatches = str.match(regex1);
    if(arrMatches==null) return 0;
    return arrMatches.length;
}

exports.dirname2=function (wurl) {
    if (this.substr(wurl, -1, 1) == "/") {
        return this.substr(wurl, 0, -1);
    } else {
        return wurl.replace(/\/[^\/]+$/gi, '');
    }
}

exports.urldecode=function (url){
    return decodeURIComponent(url);
}

exports.urlencode=function (url){
    return encodeURIComponent(url);
}
exports.quanurl=function (subUrl, url, baseurl) {
    if (this.is_array(subUrl) || subUrl == "") return "";
    baseurl = this.preg_replace("(http\\:\\/\\/[^\\/]+?)$", "\\1/", baseurl);
    subUrl = this.str_replace('this.preg_replace("(http\\:\\/\\/[^\\/]+?)$", "\\1/", baseurl)\\', "/", subUrl);
    subUrl = this.str_replace('&', "&", subUrl);
    subUrl = this.preg_replace("/^\\.\\?/", "?", subUrl);
    wurl = (baseurl) ? baseurl : url;
    wurl = this.preg_replace("\\?.*$", "", wurl);
    mm = new Array();
    this.preg_match_all("(http\\:\\/\\/([^\\/]*?))(.*)$", wurl, mm);
    host = mm[2][0];

    if (this.substr(subUrl, 0, 7) == "http://") {
        newurl = subUrl;
    } else if (this.preg_match("^\\/", subUrl)) {
        newurl = "http://"+host+subUrl;
    } else if (this.preg_match("^\\.\\.\\/", subUrl)) {
        tmsuburl = subUrl;
        tempparentUrl = wurl;
        nn = new Array();
        this.preg_match_all("(\\.\\.\\/)", subUrl, nn);
        for (i = 0; i < nn[1].length; i++) {
            tmsuburl = this.preg_replace("^\\.\\.\\/", "", tmsuburl);
            tempparentUrl = this.preg_replace("(?!<\\/)\\/[^<>\\/]*?\\/[^<>\\/]*?$", "/", tempparentUrl);
        }
        newurl = this.preg_replace("\/$", "", tempparentUrl) + "/" + tmsuburl;
    } else if (this.preg_match("^[^\\.\\/\\?]", subUrl)) {
        nna = new Array();
        this.preg_match("^(.*?)\/", subUrl, nna);
        nnb = new Array();
        this.preg_match("http\\:\\/\\/.*?\\/(.*?)\\/", wurl, nnb);
        if (nnb[1] == nna[1]) {
            newurl = "http://" + host + "/" + subUrl;
        } else {
            newurl = this.dirname2(wurl) + "/" + subUrl;
        }
    } else if (this.preg_match("^\\?", subUrl)) {
        newurl = this.preg_replace("\\?.*?$", "", wurl) + subUrl;
    } else {
        newurl = this.preg_replace("\/[^\\/]*?$", "/", wurl) + subUrl;
    }
    newurl = this.preg_replace("\\/\\.\\/", "/", newurl);
    newurl = this.preg_replace("\\/http\:\\/", "/", newurl);
    return newurl;
}

function ergodic(obj,indentation){
    var indent = "  " + indentation;
    if(obj.constructor == Array || obj.constructor == Object){
        for(var p in obj){
            if(obj[p].constructor == Array|| obj[p].constructor == Object){
                console.log(indent + "["+p+"] => "+typeof(obj)+"");
                console.log(indent + "{");
                ergodic(obj[p], indent);
                console.log(indent + "}");
            } else if (obj[p].constructor == String) {
                console.log(indent + "["+p+"] => "+obj[p]+"");
            } else {
                console.log(indent + "["+p+"] => "+obj[p]+"");
            }
        }
    }
}

exports.print_r=function (obj) {
    console.log("{")
    ergodic(obj, "");
    console.log("}")
}


exports.is_re=function (re){
//    if(this.preg_match("(?<!\\\)\(([^\(\)](?!(?<!\\\)\))|\([^\(\)]*\)*)*$",re)){
//        return false;
//    }
    return true;
}

exports.strlen=function (str){
    if(str==undefined) return 0;
    return str.length;
}

exports.maxlen=function (arr)
{
    temp = "";
    var isstring=this.is_string(arr);
    if (this.is_array(arr)) {
        for (i = 0; i < arr.length; i++) {
            if (this.strlen(this.strim(arr[i])) > this.strlen(this.strim(temp))) {
                temp = this.strim(arr[i]);
            }
        }
    } else if (isstring) {
        if (this.strlen(this.strim(arr)) > this.strlen(this.strim(temp))) {
            temp = this.strim(arr);
        }
    }
    return this.strlen(temp);
}

exports.strim=function (str)
{
    str = this.preg_replace("\\s|　\\/", "", this.preg_replace("<\\/?(?!img|br)[^<>]*>", "", str));
    return str;
}

function preduanyuan(pre,reg,str){

}

exports.tongx=function (str, nr, isint)
{
    isint=(isint==undefined||isint=="")?0:isint;
    mm = this.preg_split(",|\\;", str);
    arr = Array();
    for(i=0;i<mm.lengt;i++){
        one=mm[i];
        if (this.trim(one) == "") continue;
        isints = (isint) ? "0-9\," : "^<>";
        switch (isint) {
            case 1:
                isints = "0-9\\,";
                u = "";
                break;
            case 2:
                isints = "\\u4e00-\\u9fa5A-Za-z0-9_\\'\"";
                u = "u";
                break;
            default:
                isints = "^<>";
                u = "";
        }

        re = chakai(one)+ "(?:\\:|：|：| | |<\\/?(?:strong|b|a|font|td|span|th|em|li|span|i)[^<>]*>|\\&nbsp\\;|\\s|　)*?([" + isints + "]+?)";
        nn=new Array();
        if (this.preg_match_all(re, nr, nn)) {
            for(j=0;j<nn[1].length;j++){
                onn=nn[1][j];
                if (this.trim(onn) != "") {
                    arr.push(this.clwz(onn));
                }
            }
        }


        re = "(?:<\\/?(?:strong|b|a|font|td|span|th|em|li)[^<>]*>|\\&nbsp\\;|\\s|　)([0-9\\,]+?)(?:<\\/?(?:strong|b|a|font|td|span|th|em|li|i)[^<>]*>|\\&nbsp\\;|\\s)*" + chakai(one, 1) + "(?![\\u4e00-\\u9fa5A-Za-z0-9_]|\\)|\,|，|。)";
        nn=new Array();
        if (this.preg_match_all(re, nr, nn)) {
            for(j=0;j<nn[1].length;j++){
                onn=nn[1][j];
                if (this.trim(onn) != "") {
                    arr.push(this.clwz(onn));
                }
            }
        }


        re = "<META\\s+name=\"" + chakai(one) + "\"\\s+content=\"([^<>]*)\">";
        nn=new Array();
        if (this.preg_match_all(re, nr, nn)) {
            for(j=0;j<nn[1].length;j++){
                onn=nn[1][j];
                if (this.trim(onn) != "") {
                    ar.push(this.clwz(onn));
                }
            }
        }
    }


    returns = "";
    for(j=0;j<arr.length;j++){
        oarr=arr[j];
        if (this.strlen(oarr) > this.strlen(returns)) {
            returns = oarr;
        }
    }
    return returns;
}

function chakai(str, nowei)
{
    nowei=(nowei==undefined||nowei=="")?0:nowei;
    var str = this.preg_replace("([\\u4e00-\\u9fa5])", "\\1(?:\s| |\&nbsp\;|<(?:span|b|strong)[^<>]*>(?:<\/?(?:span|b|strong)>)?)*", str);
    if (nowei) {
        str = this.substr(str, 0, "(?:\\s| |\\&nbsp\\;|<(?:span|b|strong)[^<>]*>(?:<\\/?(?:span|b|strong)>)?)*".length * (-1));
    }
    return str;
}

exports.addsla=function (yy)
{
    restr = this.str_replace("\\", "\\\\\\", yy);
    restr = this.str_replace(".*", "allall", yy);
    restr = this.str_replace(".", "\.", restr);
    restr = this.preg_replace("\\\\\\$", "\\\\\\\\\\\\$", restr);
    restr = this.preg_replace("\"", "\\\"", restr);
    restr = this.preg_replace("\\-", "\\-", restr);
    restr = this.preg_replace("\\:", "\\:", restr);
    restr = this.preg_replace("\\?", "\\?",restr);
    restr = this.preg_replace("\\/", "\\/", restr);
    restr = this.preg_replace("\\{", "\\{", restr);
    restr = this.preg_replace("\\}", "\\}", restr);
    restr = this.preg_replace("\\(", "\\(", restr);
    restr = this.preg_replace("\\)", "\\)", restr);
    restr = this.preg_replace("/\\|", "\\|",restr);
    restr = this.preg_replace("\\,", "\\,", restr);
    restr = this.preg_replace("\\!", "\\!", restr);
    restr = this.preg_replace("\\^", "\\^", restr);
    restr = this.preg_replace("\\*", ".*", restr);
    restr = this.preg_replace("\\#", "\\#", restr);
    restr = this.preg_replace("\\]", "\\]", restr);
    restr = this.preg_replace("\\[", "\\[", restr);
    restr = this.preg_replace("\\+", "\\+", restr);
    restr = this.preg_replace("((\\\\s\\+)?(\\\\n)?\\\\s)+", "\\\s+", restr);
    restr = this.preg_replace("(?-i)MMM$", "", $restr);
    restr = this.preg_replace("/(?-i)\\\\s\+MMM\\\\s\+", "[\s\\n]+", restr);
    restr = this.str_replace("allall", ".*", restr);
    return restr;
}

exports.clwz=function (str)
{
    str = this.preg_replace("\\'(.*)\\'.*$", "\\1", str);
    str = this.preg_replace("'|\"|\\\\\"|null|【|】|：|\\:", "", str);
    str = this.preg_replace("/([0-9]+)[\\u4e00-\\u9fa5<]*$", "\\1", str);
    return str;
}


exports.cltitle=function (str)
{
    str = this.preg_replace("\\\'", "'", str);
    str = this.preg_replace("\\\\\"", '"', str);
    return str;
}

exports.htmltotxt=function (str, n, thisurl,thisbaseur,lie_a,rs)
{
    n=(n==""||n==undefined)?0:n;
    thisurl=(thisurl==""||thisurl==undefined)?"":thisurl;
    thisbaseurl=(thisbaseurl==""||thisbaseurl==undefined)?"":thisbaseurl;
    lie_a=(lie_a==""||lie_a==undefined)?false:lie_a;
    str = this.trim(str);
    str = this.strip_tags2(str, "strong|b|p|img|br|td|table|tr|ul|li|span|hr",lie_a);
    nn00=new Array();nn00[0]=new Array();
    tstr=str.replace(/(width|height|\=|\.|width\s)>/gi,"\\1&gt;");
    this.preg_match_all("<img.*>", tstr, nn00);
    for (i4 = 0; i4 < nn00[0].length; i4++) {
        tmp=this.preg_replace("\\\\(?!'|\")","/",nn00[0][i4]);
        nnn3=new Array();nnn3[1]=new Array();
        this.preg_match_all("file\\s*\\=\\s*\\\?\\\"([^<>]*)\\\??\\\"", tmp, nnn3);
        var src = this.trim(nnn3[1][0]);
        if (src == "") {
            nnn2=new Array();nnn2[1]=new Array();
            this.preg_match_all("original\\s*\=\\s*\\\\\\?\\\"([^<>]*)\\\\\\??\\\"", tmp, nnn2);
            src = this.trim(nnn2[1][0]);
        }
        if (src == "") {
            nnn2=new Array();nnn2[1]=new Array();
            this.preg_match_all("(?:real_src|data-lazyload-src|data-original|crs|src[0-9]+)\\s*\\=\s*\\\\\\?\\\"([^<>]*)\\\\\\??\\\"", tmp, nnn2);
            src = this.trim(nnn2[1][0]);
        }
        if (src == "") {
            nnn2=new Array();nnn2[1]=new Array();
            this.preg_match_all("src[0-9\\s]*\\=[\\s\\\\\\?\\\"\\\']*?([^<>\\s\\\'\\\"]*?)", tmp, nnn2);
            src = this.trim(nnn2[1][0]);
        }
        if (rs.loadimg == 1) {
            str = this.str_replace(nn00[0][i4], "\r\n[img]http://collect.longsunhd.com/source/plugin/yzs1013_pldr/getimg.php?url=" + this.surlencode(this.quanurl(this.trim(src), thisurl,thisbaseurl)) + "[/img]\r\n<p>\r\n", str);
        } else {
            str = this.str_replace(nn00[0][i4], "\r\n&nbsp;\r\n[img]" + this.quanurl(this.trim(src), thisurl,thisbaseurl) + "[/img]\r\n<p>\r\n&nbsp;\r\n", str);
        }
    }
    str = this.preg_replace("\\&ldquo\\;", "\"", str);
    str = this.preg_replace("\\&rdquo\\;", "\"", str);
    str = this.preg_replace("<(\\/?)\s*(br|p)[^<>]*>", "\r\n", str);
    str = this.preg_replace("(\\r\\s*\\n)+", "\r\n", str);
    str = this.preg_replace("<(\\/?)(td|table|tr|li|ul)\\b([^<>]*)>", "", str);
    str = this.preg_replace("\\[img\\][^<>\\[\\]]*Array\\[\/img\\]", "", str);
    str = this.preg_replace("^\\s*　　\\s*(http\:\/\/[^<>]*\.jpg)\\s*$", "\r\n　　[img]\\1[/img]\r\n", str);
    str = this.preg_replace("([\\r\\n](\\s|　)*[\\r\\n])+", "\r\n", str);
    str = this.preg_replace("\\&[a-z]+\\;", "", str);
    str = this.preg_replace("(\\]|\\。|\\；|\\？)(　|\\s)+", "\\1\r\n　　", str);
    str = this.trim(this.preg_replace("^(　|\\s|\\&nbsp\\;)＋", "\r\n　　", str));
    str = this.str_replace('\\"', '"', str);
    return this.trim(str);
}

exports.gethost=function (url){
    re=/http\:\/\/(?:[^<>\.]+\.)?([^<>\/]+(\.(com|gov|edu|org)(?=\/|$|\.cn)|\.cn(?=\/|$|\:)|\.net|\.cc|\.tv|\.hk|\.tw)+)/gi
    nn=re.exec(url)
    host=nn[1];
    return host;
}

exports.gethost2=function (url){
    re=/http\:\/\/((?:[^<>\.]+\.)?[^<>\/]+(\.(com|gov|edu|org)(?=\/|$|\.cn)|\.cn(?=\/|$|\:)|\.net|\.cc|\.tv|\.hk|\.tw)+)/gi
    nn=re.exec(url)
    host2=nn[1];
    return host2;
}

exports.is_zw=function (str)
{
    str = this.preg_replace("[\\r\\n]|$|<(?!img)[^<>]*>", "", str);
    if (this.preg_match_all("([\\u4e00-\\u9fa5]|。|，|？|！|[^<>\\/\\\\]){20,}", str, nn) || this.preg_count("\\[img\\]|<img|。|，|？|！", str) > 1 || this.preg_match("<img[^<>]*|\\[img\\]", str)) {
        return true;
    }
    return false;
}

exports.array_merge = (function(){
    var concat_ = function(arr1, arr2) {
        for (var i=arr2.length-1;i>=0;i--) {
              if (arr2[i] === undefined || arr2[i] === null) {
                    continue;
              }
            arr1.indexOf(arr2[i]) === -1 ? arr1.push(arr2[i]) : 0;
        }
    };

    return function(arr) {
        var result = arr.slice();
        for (var i=arguments.length-1;i>=1;i--) {
            concat_(result, arguments[i]);
        }
        return result;
    };
}());

exports.array_merge2=function (arr1, arr2)
{
    if (arr1.length < arr2.length) {
        t = arr1;
        arr1 = arr2;
        arr2 = t;
    }
    newarr = arr1;
    for (i = 0; i < arr1.length; i++) {
        if (this.is_array(arr2[i])) newarr[i] = this.array_merge(arr1[i], arr2[i]);
    }
    return newarr;
}


exports.array_merge3=function (oldarr,arr,aaname){
    aaname=(aaname==""||aaname==undefined)?"Array":aaname;
    a=1;
    if(!name_exists(arr)){
        for(i=0;i<arr[1].length;i++){
            oldarr[0]=oldarr[0].push(arr[0][i]);
            oldarr[1]=oldarr[1].push(arr[1][i]);
            oldarr[2]=oldarr[2].push(arr[2][i]);
        }
    }else{
        for(k=0;k<arr.length;k++){
            v=arr[k];
            if(is_int(k)) continue;
            if(this.is_array(v)&& v.length>1){
                oldarr[0]=oldarr[0].push("");
                oldarr[1]=oldarr[1].push(this.trim(aaname));
                oldarr[2]=oldarr[2].push(delnamearr(arr));
                break;
            }else{
                oldarr[0]=oldarr[0].push("");
                oldarr[1]=oldarr[1].push(this.trim(k));
                oldarr[2]=oldarr[2].push(trim(v[0]));
            }
        }
    }
    return oldarr;
}


exports.array_merge4=function ($oldarr,$arr,$aaname){
    aaname=(aaname==""||aaname==undefined)?"Array":aaname;
    a=1;
    if(!name_exists($arr)){
        for(i=0;i<arr[1].length;i++){
            oldarr[0]=oldarr[0].push(arr[0][i]);
            oldarr[1]=oldarr[1].push(arr[1][i]);
            oldarr[2]=oldarr[2].push(arr[2][i]);
        }
    }else{
        for(k=0;k<arr.length;k++){
            v=arr[k];
            if(is_int($k)) continue;
            if(is_array(v)&&count(v)>1){
                oldarr[0]=oldarr[0].push("");
                oldarr[1]=oldarr[1].push(this.trim(k));
                oldarr[2]=oldarr[2].push(trim(v));
                break;
            }else{
                oldarr[0]=oldarr[0].push("");
                oldarr[1]=oldarr[1].push(this.trim(k));
                oldarr[2]=oldarr[2].push(trim(v[0]));
            }
        }
    }
    return oldarr;
}

exports.strtolower=function(str){
    return str.toLowerCase();
}

exports.strtolower=function(str){
    return str.toUpperCase();
}


function SHA256(s){

    var chrsz   = 8;
    var hexcase = 0;

    function safe_add (x, y) {
        var lsw = (x & 0xFFFF) + (y & 0xFFFF);
        var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
        return (msw << 16) | (lsw & 0xFFFF);
    }

    function S (X, n) { return ( X >>> n ) | (X << (32 - n)); }
    function R (X, n) { return ( X >>> n ); }
    function Ch(x, y, z) { return ((x & y) ^ ((~x) & z)); }
    function Maj(x, y, z) { return ((x & y) ^ (x & z) ^ (y & z)); }
    function Sigma0256(x) { return (S(x, 2) ^ S(x, 13) ^ S(x, 22)); }
    function Sigma1256(x) { return (S(x, 6) ^ S(x, 11) ^ S(x, 25)); }
    function Gamma0256(x) { return (S(x, 7) ^ S(x, 18) ^ R(x, 3)); }
    function Gamma1256(x) { return (S(x, 17) ^ S(x, 19) ^ R(x, 10)); }

    function core_sha256 (m, l) {
        var K = new Array(0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0xFC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x6CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2);
        var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19);
        var W = new Array(64);
        var a, b, c, d, e, f, g, h, i, j;
        var T1, T2;

        m[l >> 5] |= 0x80 << (24 - l % 32);
        m[((l + 64 >> 9) << 4) + 15] = l;

        for ( var i = 0; i<m.length; i+=16 ) {
            a = HASH[0];
            b = HASH[1];
            c = HASH[2];
            d = HASH[3];
            e = HASH[4];
            f = HASH[5];
            g = HASH[6];
            h = HASH[7];

            for ( var j = 0; j<64; j++) {
                if (j < 16) W[j] = m[j + i];
                else W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);

                T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
                T2 = safe_add(Sigma0256(a), Maj(a, b, c));

                h = g;
                g = f;
                f = e;
                e = safe_add(d, T1);
                d = c;
                c = b;
                b = a;
                a = safe_add(T1, T2);
            }

            HASH[0] = safe_add(a, HASH[0]);
            HASH[1] = safe_add(b, HASH[1]);
            HASH[2] = safe_add(c, HASH[2]);
            HASH[3] = safe_add(d, HASH[3]);
            HASH[4] = safe_add(e, HASH[4]);
            HASH[5] = safe_add(f, HASH[5]);
            HASH[6] = safe_add(g, HASH[6]);
            HASH[7] = safe_add(h, HASH[7]);
        }
        return HASH;
    }

    function str2binb (str) {
        var bin = Array();
        var mask = (1 << chrsz) - 1;
        for(var i = 0; i < str.length * chrsz; i += chrsz) {
            bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32);
        }
        return bin;
    }

    function Utf8Encode(string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    }

    function binb2hex (binarray) {
        var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
        var str = "";
        for(var i = 0; i < binarray.length * 4; i++) {
            str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
            hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8  )) & 0xF);
        }
        return str;
    }

    s = Utf8Encode(s);
    return binb2hex(core_sha256(str2binb(s), s.length * chrsz));

}

exports.utf8encode=function(string){
    if(string==undefined) return "";
    string = string.replace(/\r\n/gi,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }
        return utftext;
}

exports.surlencode=function(url)
{
    if (this.preg_match("/http%3A%2F%2F/Uisx", url)) {
        return url;
    }
    url = this.urlencode(this.str_replace("%", "BAIFENHAO", url));
    return url;
}

exports.danweiarray=function (array)
{
    newarr = new Array();
    for (k=0;k<array.length;k++) {
    v=array[k];
        newarr[k] = v[0];
    }
    return newarr;
}

exports.hasimg=function(str)
{
    if (this.preg_match("/src=/gi", str)) {
        return true;
    }
    return false;
}

exports.getwrite=function(url,rs,cb){
    var request_timer = null;
    require("request").get({ url : url ,encoding : null} ,function(err, response, body){
        clearTimeout(request_timer);
        // 等待响应15秒超时
        var response_timer = setTimeout(function() {
            console.log('Response Timeout.');
            //response.destroy();
            cb("");
            return;
        }, 7000);
        var charset="utf-8";
        if(body==null||body==undefined) return "";
        var arr=body.toString().match(/<meta([^>]*?)>/g);
        if(arr){
            arr.forEach(function(val){
                var match=val.match(/charset\s*=\s*(.+)\"/);
                if(match && match[1]){
                    if(match[1].substr(0,1)=='"')match[1]=match[1].substr(1);
                    charset=match[1].trim();
                    return false;
                }
            })
        }
        re=/(gb2312|utf8|utf-8|gbk)/gi;
        nn=charset.match(re);
        charset=(nn.length>0)?nn[0]:charset;
        var data = require('iconv-lite').decode(body, charset);
        filename = "d:\\temp\\" + url.replace(/\/|\:|\?|\=|\&|\-|%|;|-/gi, "").replace(/\//, "\\").substring(0, 200);
        filename = filename.trim();
        re=/。|<img/
        if(re.test(data)) {
            var fs = require('fs');
            fs.writeFile(filename, data, function (err) {
                if (err) throw err;
                console.log("写入" + url);
                cb(data);
            });
        }
    })
}